package com.example.demoexcel.controller;

import com.alibaba.fastjson.JSON;
import com.example.demoexcel.dto.Test;
import com.kwin.excel.annotation.ResponseExcel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.kwin.excel.annotation.RequestExcel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : wangkai
 * @version V1.0
 * @Package com.example.demoexcel.controller
 * @Description:
 * @date 2021年10月19日 11:34
 **/
@RestController
public class TestController {
    
    @PostMapping("test")
    public String test(@RequestExcel List<Test> list) {
    
        return JSON.toJSONString(list);
    }
    
    @GetMapping("test2")
    @ResponseExcel
    public List<Test> test2() {
        List<Test> list = new ArrayList<>();
        Test test = null;
        for(int i = 0 ; i < 10; i++) {
            test = new Test();
            test.setHa("ha" + i);
            test.setUsername("name" + i);
            list.add(test);
        }
        return list;
    }
}
